package de.jmda.mproc.swingui;


import java.io.File;
import java.io.StringWriter;
import java.io.Writer;
import java.util.ArrayList;
import java.util.LinkedList;
import java.util.List;

import javax.xml.bind.JAXBContext;
import javax.xml.bind.JAXBException;
import javax.xml.bind.Marshaller;
import javax.xml.bind.Unmarshaller;

import org.junit.After;
import org.junit.AfterClass;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Test;

import de.jmda.mproc.swingui.JPanelFileSetJavaSourceFilesModel;
import de.jmda.mproc.swingui.JPanelVisualProcessorConfigurationModel;
import de.jmda.mproc.swingui.JPanelVisualProcessorModel;
import de.jmda.util.fileset.FileSetJavaFilesOnly;
import de.jmda.util.fileset.FileSet.RuleSetUpdateMode;
import de.jmda.util.gui.swing.JPanelFavouritesModel;

public class JUTJPanelLaunchAnnotationProcessingConfigurationModel
{
	private static Marshaller   MARSHALLER;
	private static Unmarshaller UNMARSHALLER;

	@BeforeClass
	public static void setUpBeforeClass() throws Exception
	{
		JAXBContext jaxbContext =
				JAXBContext.newInstance(
						JPanelVisualProcessorConfigurationModel.class);
		
		MARSHALLER = jaxbContext.createMarshaller();
		
		MARSHALLER.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, Boolean.TRUE);
		
		UNMARSHALLER = jaxbContext.createUnmarshaller();
	}

	@AfterClass
	public static void tearDownAfterClass() throws Exception
	{
		MARSHALLER = null;
		UNMARSHALLER = null;
	}

	@Before
	public void setUp() throws Exception
	{
	}

	@After
	public void tearDown() throws Exception
	{
	}

	@Test
	public void testMarshalling() throws JAXBException
	{
		List<String> annotationProcessorClassNames = new ArrayList<String>();
		
		annotationProcessorClassNames.add("annotationProcessorClassName 1");
		annotationProcessorClassNames.add("annotationProcessorClassName 2");
		annotationProcessorClassNames.add("annotationProcessorClassName 3");
		
		List<File> favourites = new LinkedList<File>();
		
		favourites.add(new File("favourite file 1"));
		favourites.add(new File("favourite file 2"));
		favourites.add(new File("favourite file 3"));
		
		JPanelFavouritesModel jPanelFavouritesModel =
				new JPanelFavouritesModel(favourites);
		
		FileSetJavaFilesOnly fileSetJavaFilesOnly = new FileSetJavaFilesOnly();
		
		fileSetJavaFilesOnly.includeDirectory(
				new File("include directory 1"), RuleSetUpdateMode.ADD_RULE);
		fileSetJavaFilesOnly.includeDirectory(
				new File("include directory 2"), RuleSetUpdateMode.ADD_RULE);
		fileSetJavaFilesOnly.includeDirectory(
				new File("include directory 3"), RuleSetUpdateMode.ADD_RULE);
		
		JPanelFileSetJavaSourceFilesModel jPanelFileSetJavaSourceFilesModel =
				new JPanelFileSetJavaSourceFilesModel(
						fileSetJavaFilesOnly, jPanelFavouritesModel);

		JPanelVisualProcessorModel
				jPanelVisualProcessorModel =
						new JPanelVisualProcessorModel(
								"configuration name 1",
								annotationProcessorClassNames,
								jPanelFileSetJavaSourceFilesModel);

		List<JPanelVisualProcessorModel> annotationProcessingModels =
				new LinkedList<JPanelVisualProcessorModel>();
		
		annotationProcessingModels.add(jPanelVisualProcessorModel);
		
		JPanelVisualProcessorConfigurationModel
				jPanelVisualProcessorConfigurationModel =
						new JPanelVisualProcessorConfigurationModel(
								annotationProcessingModels);

		Writer writer = new StringWriter();
		
		MARSHALLER.marshal(
				jPanelVisualProcessorConfigurationModel, writer);
		
		System.out.println(writer.toString());
	}
}